const conf = require('../conf/conf.json')
const filters = require('../conf/dictionary.json').filter

class Filter {
    constructor(key, defaultMsg, ...params) {
        this._key = key
        this._params = params || []
        this._default = defaultMsg || ''
    }

    get key() {
        return this._key
    }

    toString() {
        return conf.translate && filters[this._key] ? filters[this._key].format(...this._params) : this._default
    }
}

function translateFilters(arr) {
    const result = []
    if (!arr) return result
    for (const f of arr) {
        if (!f) continue
        if (f.key === 'ignoreAll') {
            return [filters[f.key].toString()]
        }
        result.push(f.toString())
    }
    return result
}

module.exports = {
    Filter,
    translateFilters
}